package com.aash.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.aash.persistence.dao.UserDao;
import com.aash.persistence.exception.DaoException;
import com.aash.service.model.User;

@Component
public class UserServiceImpl extends GenericService<com.aash.persistence.model.User, User> implements UserService {

	private final static transient Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
	
	public UserServiceImpl() {
		super(com.aash.persistence.model.User.class, User.class);
	}

	@Autowired
	private UserDao userDao;
	
	@Override
	public void createUser(String email, String name) {
		User user = new User();
		user.setEmail(email);
		user.setName(name);
		userDao.create(getDaoModel(user));
		logger.info("User <" + user.getName() + "> created");
	}

	@Override
	public User getUserByEmail(String email) throws DaoException {
		return getServiceModel(userDao.getUserByEmail(email));
	}

}
